﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using CommonExtensions.StringExtensions;
using Xunit;

namespace CommonExtensions.Tests
{
    public class StringExtensionsTests
    {
        [Fact]
        public void IsNullOrEmptyShouldReturnTrueIfNull()
        {
            string str = null;
            Assert.True(str.IsBlank());
        }

        [Fact]
        public void IsNullOrEmptyShouldReturnTrueIfEmpty()
        {
            string str = string.Empty;
            Assert.True(str.IsBlank());
        }

        [Fact]
        public void IsNullOrEmptyShouldReturnFalseIfNotNullEmpty()
        {
            Assert.False("a".IsBlank());
        }

        [Fact]
        public void CapitalizeShouldReturnNullIfNull()
        {
            string str = null;
            Assert.Null(str.Capitalize());
        }

        [Fact]
        public void CapitalizeShouldCapitalizeString()
        {
            var testCases = new Dictionary<string, string>()
                                {
                                    {string.Empty, string.Empty},
                                    {"a", "A"},
                                    {"abc", "Abc"},
                                    {"Abc", "Abc"},
                                    {"abcDef", "AbcDef"},
                                    {"AbcDef", "AbcDef"},
                                    {"abc def", "Abc def"},
                                    {"Abc def", "Abc def"},
                                    {"Abc Def", "Abc Def"},
                                };

            foreach (KeyValuePair<string,string> testCase in testCases)
            {
                Assert.Equal(testCase.Value, testCase.Key.Capitalize());
            }
        }

        [Fact]
        public void HumanizeShouldReturnNullIfNull()
        {
            string str = null;
            Assert.Null(str.Humanize());
        }

        [Fact]
        public void HumanizeShouldHumanizeString()
        {
            var testCases = new Dictionary<string, string>()
                                {
                                    {string.Empty, string.Empty},
                                    {"a", "A"},
                                    {"abc", "Abc"},
                                    {"Abc", "Abc"},
                                    {"ABCd", "AB Cd"},
                                    {"abcDef", "Abc Def"},
                                    {"AbcDef", "Abc Def"},
                                    {"abc def", "Abc def"},
                                    {"Abc def", "Abc def"},
                                    {"ABc def", "A Bc def"},
                                    {"Abc Def", "Abc Def"},
                                    {"Abc DEf", "Abc D Ef"},
                                    {"ABc DEf", "A Bc D Ef"},
                                };

            foreach (KeyValuePair<string, string> testCase in testCases)
            {
                Assert.Equal(testCase.Value, testCase.Key.Humanize());
            }
        }

        [Fact]
        public void TitleizeShouldReturnNullIfNull()
        {
            string str = null;
            Assert.Null(str.Titleize());
        }

        [Fact]
        public void TitleizeShouldTitleizeString()
        {
            var testCases = new Dictionary<string, string>()
                                {
                                    {string.Empty, string.Empty},
                                    {"a", "A"},
                                    {"abc", "Abc"},
                                    {"Abc", "Abc"},
                                    {"ABCd", "AB Cd"},
                                    {"abcDef", "Abc Def"},
                                    {"AbcDef", "Abc Def"},
                                    {"abc def", "Abc Def"},
                                    {"Abc def", "Abc Def"},
                                    {"ABc def", "A Bc Def"},
                                    {"Abc Def", "Abc Def"},
                                    {"Abc DEf", "Abc D Ef"},
                                    {"ABc DEf", "A Bc D Ef"},
                                };

            foreach (KeyValuePair<string, string> testCase in testCases)
            {
                Assert.Equal(testCase.Value, testCase.Key.Titleize());
            }
        }
    }
}